package com.ruoyi.web.exams.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.exams.domain.ExamAnswers;
import com.ruoyi.web.exams.dto.PostAnswersVo;
import com.ruoyi.web.exams.service.IExamAnswersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 答题卡条目Controller
 *
 * @author 范书铭
 * @date 2024-10-02
 */
@Api("答题卡条目Controller")
@RestController
@RequestMapping("/exam/answers")
public class ExamAnswersController extends BaseController {
    @Autowired
    private IExamAnswersService examAnswersService;

    /**
     * 查询答题卡条目列表
     */
    @ApiOperation("查询答题卡条目列表")
    @PreAuthorize("@ss.hasPermi('exam:answers:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamAnswers examAnswers) {
        startPage();
        List<ExamAnswers> list = examAnswersService.selectExamAnswersList(examAnswers);
        return getDataTable(list);
    }

    /**
     * 导出答题卡条目列表
     */
    @ApiOperation("导出答题卡条目列表")

    @PreAuthorize("@ss.hasPermi('exam:answers:export')")
    @Log(title = "答题卡条目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamAnswers examAnswers) {
        List<ExamAnswers> list = examAnswersService.selectExamAnswersList(examAnswers);
        ExcelUtil<ExamAnswers> util = new ExcelUtil<ExamAnswers>(ExamAnswers.class);
        util.exportExcel(response, list, "答题卡条目数据");
    }

    /**
     * 获取答题卡条目详细信息
     */
    @ApiOperation("获取答题卡条目详细信息")

    @PreAuthorize("@ss.hasPermi('exam:answers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(examAnswersService.getById(id));
    }

    /**
     * 新增答题卡条目
     */
    @ApiOperation("新增答题卡条目")

    @PreAuthorize("@ss.hasPermi('exam:answers:add')")
    @Log(title = "答题卡条目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamAnswers examAnswers) {
        return toAjax(examAnswersService.save(examAnswers));
    }

    /**
     * 修改答题卡条目
     */
    @ApiOperation("修改答题卡条目")

    @PreAuthorize("@ss.hasPermi('exam:answers:edit')")
    @Log(title = "答题卡条目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamAnswers examAnswers) {
        return toAjax(examAnswersService.save(examAnswers));
    }

    /**
     * 删除答题卡条目
     */
    @ApiOperation("答题卡条目")

    @PreAuthorize("@ss.hasPermi('exam:answers:remove')")
    @Log(title = "答题卡条目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examAnswersService.removeByIds(Arrays.asList(ids)));
    }
    @ApiOperation("用户答题")

    @PreAuthorize("@ss.hasPermi('exam:answers:edit')")
    @Log(title = "用户答题", businessType = BusinessType.UPDATE)
    @PostMapping("/postAnswer")
    public AjaxResult postAnswer(@RequestBody PostAnswersVo postAnswersVo) {
        return toAjax(examAnswersService.postAnswer(postAnswersVo));
    }

}
